package com.lianzhihui.romeex.mvp.model;

import android.content.Context;

import com.lianzhihui.romeex.bean.TradeRecordBean;
import com.lianzhihui.romeex.bean.TradeRecordEarningsBean;
import com.lianzhihui.romeex.net.APIConstant;
import com.lianzhihui.romeex.net.HttpManager;
import com.lianzhihui.romeex.net.HttpManagerCallback;
import com.lianzhihui.romeex.net.ResultData;
import com.lianzhihui.romeex.utils.GsonUtil;
import com.lianzhihui.romeex.utils.LogUtil;
import com.zhouyou.http.exception.ApiException;
import com.zhouyou.http.model.HttpParams;

/**
 * @ProjectName: romeex
 * @Package: com.lianzhihui.romeex.mvp.model.base
 * @ClassName: InvitationModellmp
 * @Description: java类作用描述
 * @Author: zhanghong
 * @CreateDate: 2020/11/9 18:18
 * @UpdateUser: 更新者：
 * @UpdateDate: 2020/11/9 18:18
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */
public class TradeRecordModelImp {


    private Context context;
    TradeRecordInterface callback;

    public TradeRecordModelImp(Context context, TradeRecordInterface i) {
        this.context = context;
        this.callback = i;
    }

    public void requestTradeRecord(int page, int pageSize, String coinName, String coinNameCobo, String tradeType) {
        HttpParams params = new HttpParams();
        params.put("page", String.valueOf(page));
        params.put("pageSize", String.valueOf(pageSize));
        params.put("coinName", coinName);
        params.put("coinNameCobo", coinNameCobo);
        params.put("tradeType", tradeType);
//        交易类型 0 全部 1 转账 2 收款 3 划转
        new HttpManager(context, new HttpManagerCallback() {
            @Override
            public void onSuccess(ResultData o) {
                LogUtil.info("InvitationModelImp:", o.getCode() + "");
                if (o.getCode() == 200 && null != o.getData()) {
                    TradeRecordBean bean = GsonUtil.GsonToBean(o.getData(), TradeRecordBean.class);
                    callback.responseSuccess(bean);
                } else {
                    callback.responseFailed(o.getCode(), o.getMsg());
                }
            }

            @Override
            public void onError(ApiException e) {
//                ToastUtils.showShort(MyApplication.mContext.getResources().getString(R.string.text_net_error));
                callback.responseFailed(-1, "ApiException");
            }
        }).post(APIConstant.TRADE_RECORD, params);
    }

    public void requestWalletProfitlist(int page, int pageSize) {
        HttpParams params = new HttpParams();
        params.put("page", String.valueOf(page));
        params.put("pageSize", String.valueOf(pageSize));

        new HttpManager(context, new HttpManagerCallback() {
            @Override
            public void onSuccess(ResultData o) {
                LogUtil.info("InvitationModelImp:", o.getCode() + "");
                if (o.getCode() == 200 && null != o.getData()) {
                    TradeRecordEarningsBean bean = GsonUtil.GsonToBean(o.getData(), TradeRecordEarningsBean.class);
                    callback.responseWalletProfitlistSuccess(bean);
                } else {
                    callback.responseFailed(o.getCode(), o.getMsg());
                }
            }

            @Override
            public void onError(ApiException e) {
//                ToastUtils.showShort(MyApplication.mContext.getResources().getString(R.string.text_net_error));
                callback.responseFailed(-1, "ApiException");
            }
        }).post(APIConstant.WALLET_PROFITLIST, params);
    }
}
